@extends('admin.layout')
@section('title',$title)
@section('content')
     <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                分类管理
                <small>在这里可以查看分类
                @if(session('info'))
                       <span style="color: red;" class="edit">{{session('info')}}</span>     
                @endif
                </small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{url('/admin/user/index')}}"><i class="fa fa-dashboard"></i>主页</a></li>
                <li><a href="{{url('/admin/type')}}">分类管理</a></li>
                <li class="active">浏览分类</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速浏览分类</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">

                            <form action="{{ url('/admin/type')}}">

                            <div class="row">
                                <div class="col-md-1">
                                    <div class="form-group">
                                    <select class="form-control" name="num">
                                        <option @if(!empty($request['num']) &&  $request['num'] == '20') selected="selected" @endif value="20">分页</option>
                                        <option @if(!empty($request['num']) &&  $request['num'] == 1) selected="selected" @endif>1</option>
                                        <option @if(!empty($request['num']) &&  $request['num'] == 2) selected="selected" @endif>2</option>
                                        <option @if(!empty($request['num']) &&  $request['num'] == 3) selected="selected" @endif>3</option>
                                        <option @if(!empty($request['num']) &&  $request['num'] == 4) selected="selected" @endif>4</option>
                                    </select>
                                    </div>
                                    </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                    <select class="form-control" name="sort">
                                        <option value="0">分类</option>
                                    @foreach($data as $sort)
                                        <option value="{{$sort->tid}}">{{$sort->tname}}</option>
                                    @endforeach    
                                    </select>
                                    </div>
                                </div>
                                <div class="col-md-4 col-md-offset-5">
                                    <div class="input-group input-group">
                                        <input type="text" name="keywords" value="{{$request['keywords'] or ''}}" class="form-control">
                                        <span class="input-group-btn">
                                          <button class="btn btn-info btn-flat" type="submit">搜索</button>
                                        </span>
                                    </div><!-- /input-group -->
                                </div>

                            </div>
                            </form>
                                <thead>
                                <tr>
                                    <th>类别ID</th>
                                    <th>父类ID</th>
                                    <th>分类名称</th>
                                    <th>PATH</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $row)
                                <tr>
                                    <td>{{$row -> tid}}</td>
                                    <td>{{$row -> pid}}</td>
                                    <td>{{$row -> tname}}</td>
                                    <td>{{$row -> path}}</td>
                                    <td><a href="{{url('/admin/type/')}}/{{$row ->tid}}/edit">编辑</a><span style="color: gold">&nbsp;|&nbsp;</span><a href="{{url('/admin/type/create')}}">添加子分类</a><span style="color: gold">&nbsp;|&nbsp;</span><a href="javascript:doDel({{$row->tid}});">删除</a>
                                    </td>
                                   
                                </tr>
                                @endforeach
                                <form id="delForm" action="" method="post">
                                    {{csrf_field()}}
                                    {{method_field("DELETE")}}    
                                    </form>
                                </tfoot>
                            </table>
                            {{ $data-> appends($request) -> links() }}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->

                   
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script>
            window.onload = function()
            {
                 $('.edit').fadeOut(2000);  
            }
            function doDel(tid)
            {
                var delForm = $('#delForm');
                delForm.attr('action',"{{url('/admin/type')}}"+'/'+tid);
                delForm.submit();
            }
           

    </script>
@endsection